fix(detectors/aws/lambda): return nil error when not running on Lambda - #9464
Open
pujitha24 wants to merge 2 commits into
Open
fix(detectors/aws/lambda): return nil error when not running on Lambda#9464pujitha24 wants to merge 2 commits into
pujitha24 wants to merge 2 commits into
Conversation
Motivation: The Lambda resource detector returned a non-nil error whenever the AWS_LAMBDA_FUNCTION_NAME environment variable was unset, i.e. whenever the process was not running inside AWS Lambda. This makes the detector unusable in generic, multi-environment detector chains: any caller that treats a detector error as fatal (for example xrayconfig.NewTracerProvider, which returns the error from detector.Detect verbatim) fails outright outside of Lambda instead of simply contributing no attributes. This is inconsistent with sibling detectors in this repository, such as the EKS and ECS detectors, which return a nil error and an empty resource once they determine they are not running in their respective target environment. Approach: Change resourceDetector.Detect to return (empty, nil) instead of (empty, errNotOnLambda) when AWS_LAMBDA_FUNCTION_NAME is unset, and remove the now-unused errNotOnLambda sentinel error. The resource returned is unchanged (still empty); only the error contribution changes from non-nil to nil, matching the no-op behavior used by go.opentelemetry.io/contrib/detectors/aws/ecs and go.opentelemetry.io/contrib/detectors/aws/eks. Validation: - go test ./... in detectors/aws/lambda: all tests pass. The updated TestReturnsIfNoEnvVars asserts assert.NoError(t, err) instead of assert.Equal(t, errNotOnLambda, err); confirmed this test fails against the previous code (returns errNotOnLambda) and passes with this change, i.e. it is a genuine failing-then-passing regression test for this defect. - go build ./... and go vet ./... in detectors/aws/lambda: pass. - golangci-lint run ./... in detectors/aws/lambda: 0 issues. - go mod tidy at the repository root: no diff to go.mod/go.sum. - Searched all in-repo usages of this detector (autodetect.go, xrayconfig.go, the package example) for reliance on the old error value or type; none check errNotOnLambda specifically, so this is not a breaking change for any in-repo caller. Report: open-telemetry#8629 Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9464 +/- ##
=====================================
Coverage 84.5% 84.5%
=====================================
Files 203 203
Lines 16805 16805
=====================================
+ Hits 14204 14215 +11
+ Misses 2121 2110 -11
Partials 480 480
🚀 New features to boost your workflow:
|
ps-mir
reviewed
Aug 13, 2026
ps-mir
left a comment
Contributor
There was a problem hiding this comment.
Changelog entry needs a correction. No other concerns.
|
|
||
| ### Fixed | ||
|
|
||
| - `go.opentelemetry.io/contrib/detectors/aws/lambda` no longer returns an error when run outside of an AWS Lambda environment, matching the no-op behavior of other resource detectors. |
Contributor
There was a problem hiding this comment.
I think new entries in changelog are appended. This should move to bottom of the list.
Per review feedback from ps-mir, new entries should be appended rather than prepended. Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
Contributor
Author
|
Moved the entry to the bottom of the Fixed list, thanks for catching that. |
ps-mir
approved these changes
Aug 13, 2026
dashpole
approved these changes
Aug 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation:
The Lambda resource detector returned a non-nil error whenever the
AWS_LAMBDA_FUNCTION_NAME environment variable was unset, i.e. whenever
the process was not running inside AWS Lambda. This makes the detector
unusable in generic, multi-environment detector chains: any caller
that treats a detector error as fatal (for example
xrayconfig.NewTracerProvider, which returns the error from
detector.Detect verbatim) fails outright outside of Lambda instead of
simply contributing no attributes. This is inconsistent with sibling
detectors in this repository, such as the EKS and ECS detectors, which
return a nil error and an empty resource once they determine they are
not running in their respective target environment.
Approach:
Change resourceDetector.Detect to return (empty, nil) instead of
(empty, errNotOnLambda) when AWS_LAMBDA_FUNCTION_NAME is unset, and
remove the now-unused errNotOnLambda sentinel error. The resource
returned is unchanged (still empty); only the error contribution
changes from non-nil to nil, matching the no-op behavior used by
go.opentelemetry.io/contrib/detectors/aws/ecs and
go.opentelemetry.io/contrib/detectors/aws/eks.
Validation:
TestReturnsIfNoEnvVars asserts assert.NoError(t, err) instead of
assert.Equal(t, errNotOnLambda, err); confirmed this test fails
against the previous code (returns errNotOnLambda) and passes with
this change, i.e. it is a genuine failing-then-passing regression
test for this defect.
xrayconfig.go, the package example) for reliance on the old error
value or type; none check errNotOnLambda specifically, so this is
not a breaking change for any in-repo caller.
Report: #8629
Signed-off-by: Pujitha Paladugu 10557236+pujitha24@users.noreply.github.com
Fixes #8629